<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="styles/demo.css" />
</head>

<body>
<div id="app">
    <div id="searchBar">
        Search
        <input type="text" v-model="searchQuery" />
    </div>
    <simple-component :data="gridData" :columns="gridColumns" :filter-key="searchQuery"></simple-component>
</div>
<template id="grid-template">
    <table>
        <thead>
        <tr>
            <th v-for="(col,index) in columns">
                {{ col }}
            </th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in filteredData">
            <td>
                {{ item.name }}
            </td>
            <td>
                {{ item.age }}
            </td>
            <td>
                {{ item.sex }}
            </td>
        </tr>
        </tbody>
    </table>
</template>
</body>
<script src="js/vue.js"></script>
<script>

    Vue.component('simple-component', {
        template: "#grid-template",
        props: {
            data: Array,
            columns: Array,
            filterKey: String
        },
        computed: {
            filteredData: function () {
                var self = this;

                return self.data.filter(function (item) {
                    return item.name.indexOf(self.filterKey) !== -1;
                })
            }
        }
    });

    var demo = new Vue({
        el: "#app",
        data: {
            searchQuery: '',
            gridColumns: ['name', 'age', 'sex'],
            gridData: [
                {
                    name: 'jack',
                    age: 12,
                    sex: 'female'
                },
                {
                    name: 'tom',
                    age: 13,
                    sex: 'male'
                },
                {
                    name: 'jam',
                    age: 14,
                    sex: 'male'
                }
            ]
        }

    });

</script>

</html>
